import { useTableColumnProps } from '/@/hooks/table-column/props'
import type { SwitchEmits, SwitchProps } from 'element-plus'

export type ElTableColumnSwitchProps<
  T extends Record<string, any>,
  P extends keyof T
> = Merge<
  UseTableColumnProps<SwitchProps, T, P>,
  {
    props?: Partial<UnReadonly<SwitchProps>> & {
      onChange?: SwitchEmits['change']
      onInput?: SwitchEmits['input']
      onUpdateModelValue?: SwitchEmits['update:modelValue']
    }
  }
>

/**
 * 表格开关按钮
 * @param prop column.prop
 * @param label column.label
 * @param options tableColumn的其他属性
 * @returns tableColumn props
 */
export function useTableColumnSwitch<
  T extends Record<string, any>,
  P extends keyof T
>(prop: P, label: string, options: ElTableColumnSwitchProps<T, P> = {}) {
  return useTableColumnProps(prop, label, {
    // formatter: (row: T) => {
    //   return (
    //     <el-switch
    //       {...options.props}
    //       v-model={row[prop]}
    //       onChange={(value: SwitchProps['modelValue']) => {
    //         if (options.change) {
    //           options?.change(value, row)
    //         }
    //         if (options?.props?.onChange) {
    //           options?.props.onChange(value)
    //         }
    //       }}
    //     />
    //   )
    // },
    ...options,
    showOverflowTooltip: false,
    component: 'el-switch'
  })
}
